﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Configuration;
using System.Web.Services;

/// <summary>
///DataTableWebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class DataTableWebService : System.Web.Services.WebService
{
    public DataTableWebService()
    {
        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod]
    public DataSet GetDataSet(string tableName)
    {
        try
        {
            using (SqlConnection conn = new SqlConnection())
            {
                string connectionString = WebConfigurationManager.AppSettings["connectionString"];
                conn.ConnectionString = connectionString;
                SqlCommand command = new SqlCommand("SELECT * FROM " + tableName, conn);

                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataSet ds = new DataSet(tableName);

                adapter.Fill(ds);
                return ds;
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
}